<?php

namespace App\Services\Gallery\Model;

use App\Models\Administrator;
use App\Services\Designer\Model\Reply;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Carbon;

class ClassicCase extends Model
{
    public const SHOW_YES = 1;
    public const SHOW_NO = -1;

    public const SHIJING = 1;
    public const JINGXUAN = 2;

    public const TYPE_TEXT = [
        self::SHIJING => '业主实景案例',
        self::JINGXUAN => '精选方案',
    ];

    protected $table = 'classic_case';

    protected $fillable = [
        'title', 'thumb', 'sort', 'is_show', 'describe', 'content', 'like_count', 'view_count', 'share_count', 'remark_count','type','designer_id','is_recommend'
    ];

    protected $appends = ['type_text','creator'];

    public function getTypeTextAttribute()
    {
        return self::TYPE_TEXT[$this->type] ?? '';
    }

    public function getCreatorAttribute()
    {
        return $this->user->name;
    }

    public function user()
    {
        return $this->belongsTo(Administrator::class, 'user_id');
    }

    /**
     * 作用域：显示.
     *
     * @param $query
     *
     * @return mixed
     */
    public function scopeShow($query)
    {
        return $query->where('is_show', self::SHOW_YES);
    }

    /**
     * 作用域：不显示.
     *
     * @param $query
     *
     * @return mixed
     */
    public function scopeNotShow($query)
    {
        return $query->where('is_show', self::SHOW_NO);
    }
}
